package com.ht.api.call.func.impl.tag;

import cn.hutool.json.JSONObject;
import com.ht.api.bean.AjaxResult;
import com.ht.api.bean.LoginBean;
import com.ht.api.call.func.IFunctionCall;
import com.ht.api.db.Db;
import com.ht.api.db.DbList;
import com.ht.api.db.Entity;

/**
 * 标签关联关系查询后置函数
 */
public class TagRelationQueryFunctionCall implements IFunctionCall {

    @Override
    public String getName() {
        return "标签关联关系查询后置函数";
    }

    @Override
    public JSONObject execute(LoginBean me, JSONObject param, AjaxResult result) {
        DbList list = result.getRecords();

        for (Entity tagRelation : list) {
            String relationId = tagRelation.getStr("relation_id");
            String tagCode = tagRelation.getStr("tag_code");
            if (tagCode.equals("user")) {
                Entity user = Db.createSqlParser("user_main").select("oneid,nickname,aliasname,avatar,gender")
                        .where("main_id", relationId).where("status", 0).findOne(me.getDataSource());

                tagRelation.set("mapper_oneid", user);
            }

        }

        return null;
    }
}
